package com.moon.app;

import org.apache.commons.lang.StringUtils;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;

import com.moon.R;
import com.moon.common.AbstractActivity;

public class Welcome extends AbstractActivity implements Runnable{
	
	private boolean isFirstUse;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		
		
        tracker.setCustomVar(1, "Android", Build.VERSION.RELEASE, 1);
        tracker.setCustomVar(2, "Device", Build.MODEL + "; " + Build.DISPLAY, 1);
        tracker.setCustomVar(3, "moon", "1.0", 1);
        tracker.trackEvent("Launch", "StartApp", "Application", 1);
		
		new Thread(this).start();
	}

	@Override
	public void run() {
		try {
			Thread.sleep(2000);
			
			if(getUser()!=null && StringUtils.isNotEmpty(getUser().getName())){
	            startActivity(new Intent(Welcome.this, MainActivity.class));
	        }else{
                startActivity(new Intent(Welcome.this,LoginActivity.class));
	        }
			return;
//			SharedPreferences preferences = getSharedPreferences("isFirstUse", MODE_WORLD_READABLE);
//			Long userId = preferences.getLong("userId", 0L);
//            if(userId==0L){
//                startActivity(new Intent(Welcome.this,LoginActivity.class));
//                return;
//            }
//			if(isFirstUse){
//				startActivity(new Intent(Welcome.this,MainActivity.class));
//			}else{
//				//预留引导页面activity
//			}
//			
//			Editor editor = preferences.edit();
//			editor.putBoolean("isFirstUse", true);
//			editor.commit();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            // 阻止返回键
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
